package com.bwie.bwedu.model.impl;

import com.android.volley.Response;
import com.android.volley.VolleyError;
import com.bwie.bwedu.bean.Student;
import com.bwie.bwedu.bean.response.BaseResponse;
import com.bwie.bwedu.bean.response.MainInfoResponse;
import com.bwie.bwedu.model.AddStuListen;
import com.bwie.bwedu.model.LocalSaveModel;
import com.bwie.bwedu.utils.LogUtils;
import com.bwie.bwedu.volley.RequestAPI;

/**
 * Created by zhang on 2016/7/24.
 */
public class LocalSaveModelImpl implements LocalSaveModel {
    @Override
    public void http(String flag, String  pn,final LocalSaveModel.Listener listener){
        RequestAPI.getMainInfo(flag,pn,new Response.Listener<MainInfoResponse>() {
                    @Override
                    public void onResponse(MainInfoResponse userResponse) {
                        LogUtils.e("sssssssssssmodel_sucssssssss");
                        listener.success(userResponse);
                        LogUtils.e("ssssssssmodel_suc2sssssssssss");
                    }
                }
                , new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        LogUtils.d("-------------------------------------");
                        listener.error("网络请求失败");
                    }
                });
    }
    public void Invalidhttp(String id,final LocalSaveModel.InvalidListener invalid){
        RequestAPI.invalid(id,new Response.Listener<MainInfoResponse>() {
                    @Override
                    public void onResponse(MainInfoResponse userResponse) {
                        invalid.invalidsuccess(userResponse);
                    }
                }
                , new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        invalid.invaliderror("网络请求失败");
                    }
                });
    }
    @Override
    public void deleteHttp(String id,final DeleteListerer listener) {
        RequestAPI.localDel(id, new Response.Listener<BaseResponse>() {
                    @Override
                    public void onResponse(BaseResponse baseResponse) {
                        if (baseResponse.ok) {
                            listener.deleteSuccess(baseResponse);
                        } else {
                            listener.deleteError(baseResponse.msg);
                        }
                    }
                }
                , new Response.ErrorListener() {
                    @Override
                    public void onErrorResponse(VolleyError volleyError) {
                        listener.deleteError("网络请求失败");
                    }
                });

    }
    public void Comit(Student student, AddStuListen listen) {
        LogUtils.e("===========model============");
        RequestAPI.upLoading(student,listen);
    }


}
